﻿Imports System.Data.SqlClient
imports System.Text.RegularExpressions 
Public Class frmCauHinh
    Public Shared st As String = "0"
    Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click

        'SqlDataProvider.databasename = "QuanLyNhaTro_1065019_1065001"
        'SqlDataProvider.servername = "."


        Dim data As String = txtDatabasename.Text
        Dim server As String = txtServername.Text


        Try
            Dim CnStr As String = "Server=" & server & ";Database= " & data & ";Integrated Security=SSPI"
            Dim cn As SqlConnection = New SqlConnection(CnStr)
            Dim sql As String = "delete nhathue where manha = 0"
            Dim cmd As SqlCommand = New SqlCommand(sql, cn)
            cmd.Connection.Open()
            cmd.ExecuteNonQuery()
            cmd.Connection.Close()


            Dim w As AppSettingsWriter = New AppSettingsWriter()
            w.SetValue("CauHinh", "1")
            w.SetValue("Servername", server)
            w.SetValue("Databasename", data)

            st = "1"
            frmMain.st = "1"
            MessageBox.Show("cấu hình thành công")
            Me.Close()

        Catch ex As Exception
            MessageBox.Show("Server name , database name không đúng")
        End Try


    End Sub

    Private Sub frmCauHinh_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        If (st = "0") Then
            frmMain.Close()
        End If
    End Sub

   

    Private Sub frmCauHinh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Process.Start("..\..\Help1.chm")
        Process.Start("Help1.chm")
    End Sub
End Class